;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; settings for C programming
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; cc-mode
(defconst my-c-style
  '((c-tab-always-indent . t)
    (c-cleanup-list . (scope-operator
		       empty-defun-braces
		       defun-close-semi
		       space-before-funcall))
    (c-hanging-braces-alist . ((substatement-open after)
			       (brace-list-open)))
    (c-hanging-colons-alist . ((member-init-intro before)
			       (inher-intro)
			       (case-label after)
			       (label after)
			       (access-label after)))
    (c-offsets-alist . ((arglist-close . c-lineup-arglist)
			(substatement-open . 0)
			(case-label . 4)
			(block-open . 0)
			(knr-argdecl-intro . -)))
;    (c-echo-syntactic-information-p . t)
    )
  "My C Programming Style")
(c-add-style "PERSONAL" my-c-style)
(defun my-c-mode-common-hook ()
  ;; set personal style for current buffer
  (c-set-style "PERSONAL")
  (setq c-basic-offset 8)
  (setq tab-width 8
	indent-tabs-mode nil)
  (setq c-report-syntactic-errors t))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;; cedet
(load-file "/home/work/emacs/cedet-1.0pre7/common/cedet.el")
(require 'semantic)
(require 'semantic-ia)
(require 'semantic-gcc)
(require 'semanticdb)
;; enable the project management system
;(global-ede-mode 1)
;; enable prototype help and smart completion 
(semantic-load-enable-excessive-code-helpers)
;; enable template insertion menu
;(global-srecode-minor-mode 1)
;; enable source code folding
(global-semantic-tag-folding-mode 1)
;; no header line
(global-semantic-stickyfunc-mode -1)
(add-hook 'speedbar-load-hook (lambda () (require 'semantic-sb)))
(defun my-cedet-hook()
  (local-set-key [(control return)] 'semantic-ia-complete-symbol)
  (local-set-key "\C-c?" 'semantic-ia-complete-symbol-menu)
  (local-set-key "\C-cs" 'semantic-ia-complete-tip)
  (local-set-key "\C-cd" 'semantic-ia-fast-jump)
  (local-set-key "\C-cr" 'semantic-symref-symbol)
  (local-set-key "\C-cR" 'semantic-symref))
(add-hook 'c-mode-common-hook 'my-cedet-hook)
;; (defun my-c-mode-cedet-hook ()
;;   (local-set-key "." 'semantic-complete-self-insert)
;;   (local-set-key ">" 'semantic-complete-self-insert))
;; (add-hook 'c-mode-common-hook 'my-c-mode-cedet-hook)
;; smart completion
(defun my-indent-or-complete()
  (interactive)
  (if (looking-at "\\>")
      (hippie-expand nil)
    (indent-for-tab-command)))
(global-set-key [(control tab)] 'my-indent-or-complete)
(autoload 'senator-try-expand-semantic "senator")
(setq hippie-expand-try-functions-list
      '(senator-try-expand-semantic
	try-expand-dabbrev
	try-expand-dabbrev-visible
	try-expand-dabbrev-all-buffers
	try-expand-dabbrev-from-kill
	try-expand-list
	try-expand-list-all-buffers
	try-expand-line
	try-expand-line-all-buffers
	try-complete-file-name-partially
	try-complete-file-name
	try-expand-whole-kill))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; ECB
(add-to-list 'load-path "/home/work/emacs/ecb-2.40")
;(require 'ecb-autoloads)
(require 'ecb)
(setq ecb-tip-of-the-day nil)
(setq ecb-version-check nil)
(setq ecb-primary-secondary-mouse-buttons (quote mouse-1--C-mouse-1))
(setq ecb-tree-buffer-style 'ascii-guides)
(ecb-layout-define "cys-layout" left-right nil
                   ;; left
                   (ecb-set-methods-buffer)
                   (select-window (next-window (next-window)))
                   ;; right
                   (ecb-set-speedbar-buffer)
                   ;; (ecb-split-ver 0.6 t)
                   ;; (other-window 1)
                   ;; (ecb-set-analyse-buffer)
                   (ecb-select-edit-window)
                   )
;(defecb-window-dedicator ecb-set-cscope-buffer " *ECB cscope-buf*"
;  (switch-to-buffer "*cscope*"))
(setq ecb-layout-name "cys-layout")
;; Disable buckets so that history buffer can display more entries
(setq ecb-history-make-buckets 'never)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; cscope
(require 'xcscope)
(setq cscope-do-not-update-database t)
(setq cscope-initial-directory "/home/work/cscope")
